/*
 创建时间：2016-12-23
 创建人：admin
 描述：移动端应用js
 */
$(function () {
    //查看分配任务切换
    $(".ja-nav .nav-a").bind("click", function () {
        var obj = $(this);
        $(".ja-nav .nav-a").removeClass("na-on");
        obj.addClass("na-on");
        if (obj.html() == $(".ja-nav .nav-a").eq(0).html()) {
            $(".no-finish").show();
            $(".finish").hide();
        } else {
            $(".no-finish").hide();
            $(".finish").show();
        }
    });
    //business-index首页menu展示
    $(".bmenu tr td").each(function () {
        var obj = $(this).index();
        if ((obj + 1) % 3 == 0) {
            $(this).css({
                "border-right": 0
            });
        }
    });
    //inforeiit模拟select
    $(".bplclick").bind("click", function () {
        var obj = $(this);
        obj.next(".bpl").show();
    });
    $(".bplclose").bind("click", function () {
        $(this).parent().hide();
    });
    $(".bpl-box p").bind("click", function () {
        var obj = $(this).find("span");
        $(".bpl-box p span").removeClass("bfocus");
        obj.addClass("bfocus");
        $(this).parents(".bpl").prev("input").val($(this).text());
        $("#bpid").val($(this).data("id"));
        $(this).parents(".bpl").hide();
    });
    //buscreate多选
    $(".tinser").bind("click", function () {
        $(this).next().show();
    });
    $(".ser-con p").bind("click", function () {
        var obj = $(this).find("span");
        if (obj.hasClass("bfocus")) {
            obj.removeClass("bfocus");
        } else {
            obj.addClass("bfocus");
        }
    });
    $(".service .op-btn").bind("click", function () {
        var val = "";
        var valid = "";
        $(".service p .bfocus").each(function () {
            val += $(this).parent().text() + ",";
            valid += $(this).parent().data("id") + ",";

        });
        $(this).parents(".service").prev("input").val(val);
        $("#ckid").val(valid);
        $(".service").hide();
    });
    $(".service .back").bind("click", function () {
        $(".service").hide();
    });
    //请求城市县
    $(".tiarea").bind("click", function () {
        $(this).next().show();
        city(0, "province");
    });
    $(".area-box").on("click", "p", function () {
        var o = $(this).attr("value");
        var obj = $(this).parents(".areajax").prev("input");
        if ($(this).data("bind") == "province") {
            $("#province").val(o);
            $("#province").attr("data-name", $(this).html());
            city(o, "city");
        }
        if ($(this).data("bind") == "city") {
            $("#city").val(o);
            $("#city").attr("data-name", $(this).html());
            city(o, "county");
        }
        if ($(this).data("bind") == "county") {
            $("#county").val(o);
            $("#county").attr("data-name", $(this).html());
            $(".tiarea").val($("#province").data("name") + $("#city").data("name") + $("#county").data("name"));
            $(".areajax").hide();
        }
    });
    $(".areajax .back").bind("click", function () {
        $(".areajax").hide();
    });
});
function city(o, h) {
    $.ajax({
        type: 'post',
        url: 'http://api.zhizhukeji.com/Area/get_childs.html?pid=' + o + '',
        crossDomain: true,
        dataType: 'jsonp',
        success: function (data) {
            var list = eval(data);
            if (list.status == 1) {
                var city = list.list;
                var html = "";
                for (i = 0; i < city.length; i++) {
                    html += '<p data-bind=' + h + ' value=' + city[i].id + '>' + city[i].areaname + '</p>';
                }
                $(".area-box").html(html);
            }
        },
        error: function () {
            alert("获取失败");
        },
        beforeSend: function () {
            $(".area-box").html('<span class="argif"><span>');
        },
        complete: function () {
        }
    });
}
function delect(that) {
    var url = $(that).data("url");
    layer.open({
        content: '确定删除这条信息吗？',
        btn: ['确定', '取消'],
        yes: function (index) {
            $.ajax({
                type: 'get',
                url: url,
                success: function (data) {
                    var list = eval(data);
                    if (list.status == 0) {
                        layer.open({
                            content: list.msg,
                            skin: 'msg',
                            time: 2 //2秒后自动关闭
                        });
                        $(that).parents(".b-box").remove();
                    } else {
                        layer.open({
                            content: list.msg,
                            skin: 'msg',
                            time: 2 //2秒后自动关闭
                        });
                    }
                },
                error: function () {
                    layer.open({
                        content: '删除失败',
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                }
            });
            layer.close(index);

        }
    });
}
function thimg(that) {
    var obj = $(that);
    var url = obj.attr("src");
    layer.open({
        type: 1,
        title: false,
        closeBtn: 2,
        area: '100%',
        skin: 'layui-layer-nobg', //没有背景色
        shadeClose: true,
        content: "<img style='width:90%;margin:0 auto;' src=" + url + " />",
    });
}
function spot(that) {
    var obj = $(that);
    var url = obj.data("url");
    $.ajax({
        type: 'get',
        url: url,
        success: function (data) {
            var list = eval(data);
            if (list.status == 3) {
                layer.msg("操作成功");
                obj.remove();
                obj.parents(".site").find(".sname").next().remove().after("<span class='c_success'>【已完成】</span>");
            } else {
                layer.msg(list.msg);
            }
        },
        error: function () {
            layer.open('删除失败');
        }
    });
}
/*点击获取验证码*/
function setsecend(obj, secend) {
    var $me = this;
    $me.get = obj;
    $me.secend = secend;
    $me.num = secend;
    var url = obj.data("url");
    $me.getcode = function (get, num) {
        $me.get.bind("click", function () {
            var tel = $("#tel").val();
            if (tel == "") {
                layer.open({
                    content: "手机号不能为空",
                    skin: "msg",
                    time: 2
                });
            } else {
                if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(tel))) {
                    layer.open({
                        content: "请填写正确的手机号",
                        skin: "msg",
                        time: 2
                    });
                } else {
                    $.ajax({
                        type: 'post',
                        url: url + tel + ".html",
                        success: function (data) {
                            var list = eval(data);
                            if (list.val == "success") {
                                $me.get.html('' + num + '秒后重新获取');
                                $me.get.addClass("ps-gray");
                                $me.get.unbind("click");
                                $me.timer = setInterval(function () {
                                    $me.time();
                                }, 1000);
                            } else {
                                layer.open({
                                    content: list.msg,
                                    skin: "msg",
                                    time: 2
                                });
                            }
                        },
                        error: function (data) {
                            layer.open({
                                content: data.msg,
                                skin: "msg",
                                time: 2
                            });
                        }
                    });

                }
            }
        });
    }
    //定义秒数
    $me.time = function () {
        $me.num = $me.num - 1;
        $me.t = $me.num;
        if ($me.t > 0) {
            $me.get.html('' + $me.t + '秒后重新获取');
        } else {
            clearInterval($me.timer);
            $me.get.removeClass("ps-gray").html('获取验证码');
            $me.num = $me.secend;
            $me.getcode($me.get, $me.num);
        }
    }
    $me.getcode($me.get, $me.num);
}
/*点击获取验证码*/
/*login提交表单验证*/
function check() {
    var tel = $("#tel").val();
    if (tel == "") {
        layer.open({
            content: "手机号不能为空",
            skin: "msg",
            time: 2
        });
        return false;
    } else {
        if (!(/^1[34578]\d{9}$/.test(tel))) {
            layer.open({
                content: "请填写正确的手机号",
                skin: "msg",
                time: 2
            });
            return false;
        } else {
            if ($("#yan").val() == "") {
                layer.open({
                    content: "验证码不能为空",
                    skin: "msg",
                    time: 2
                });
                return false;
            }
        }
    }
}